//
//  KeChengNectVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/17.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "KeChengNectVC.h"

@interface KeChengNectVC ()<KeChengNextNavSelectedDelegate,KeChengXueShengViewDelegate>

@property (copy, nonatomic) NSString *attendProgressId;

@end

@implementation KeChengNectVC
- (instancetype)initWithClassID:(NSString *)classID andLessonID:(NSString *)lessonID attendProgressId:(NSString *)attendProgressId{
    if ([super init]) {
        self.classID = classID;
        self.lessonId = lessonID;
        self.attendProgressId = attendProgressId;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    self.mainw = MAINW;
    self.view.backgroundColor = MAINBACKCOLOR;
    [self.view addSubview:self.mainScrollView];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    [_mainScrollView addSubview:self.leftKeChengView];
    
}

- (void)setIsSelect:(BOOL)isSelect {
    if (isSelect == YES) {
        __weak typeof(self) weakSelf = self;
        [NSObject executeRunloop:^{
            [weakSelf.navView selectKeShiZiYuan];
        } afterDelay:0];
    }
}

- (void)addChildViewForDetailAndID:(NSString *)index{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _xueShengDetailVC = [[XueShengXiangQingVC alloc]initWothStudentID:index];
    _xueShengDetailVC.view.backgroundColor = [UIColor whiteColor];
    _xueShengDetailVC.view.frame = CGRectMake(self.mainw, 0, self.mainw, APP_HEIGHT-84);
    [self.view addSubview:_xueShengDetailVC.view];
    [_xueShengDetailVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (void)addChildViewForDetail:(int)index{
    
   
}

- (void)setWsksModel:(KeChengWeiShangKeShiModel *)wsksModel {
    _wsksModel = wsksModel;
}


#pragma mark - 这个基本每个类都要用

- (KeChengNextNavView *)navView{
    if (!_navView) {
        KeChengNextNavView *topView = [[KeChengNextNavView alloc]init];
        topView.frame = CGRectMake(0, 0, _mainw, 44);
        topView.delegate = self;
        _navView = topView;
    }
    return _navView;
}
- (KeChengXueNextWoDeZiYuanView *)keChengXueShengZiYuanView{
    if (!_keChengXueShengZiYuanView) {
        KeChengXueNextWoDeZiYuanView *view = [[KeChengXueNextWoDeZiYuanView alloc]initWithClassID:self.classID andLessonID:self.lessonId attendProgressId:self.attendProgressId withFrame:CGRectMake(self.mainw, 0, self.mainw, self.view.frame.size.height)];
        view.contVC = self;
        _keChengXueShengZiYuanView = view;
        _keChengXueShengZiYuanView.wsksModel = self.wsksModel;
    }
    return _keChengXueShengZiYuanView;
}
- (KeChengXueShengView *)leftKeChengView{
    if (!_leftKeChengView) {
        KeChengXueShengView *view = [[KeChengXueShengView alloc]initWithClassID:self.classID andLessonID:self.lessonId WithFrame:CGRectMake(0, 0, self.mainw,self.view.frame.size.height)];//initWithFrame:CGRectMake(0, 0, self.mainw,self.view.frame.size.height)];
        view.myDelagete = self;
        NSLog(@"当前代理  %@",view.myDelagete);
        _leftKeChengView = view;
    }
    return _leftKeChengView;
}
//- (void)addXueShengXiangQingView:(int)index{
//    _xueShengDetailVC = [[XueShengXiangQingVC alloc]init];
//    _xueShengDetailVC.view.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
//    [self.view addSubview:_xueShengDetailVC.view];
//    [UIView animateWithDuration:0.5 animations:^{
//        self->_xueShengDetailVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//    } completion:^(BOOL finished) {
//        
//    }];
//}
#pragma mark - 课时学生
- (void)leftButtonClick{
    currentIndex = 0;
    _mainScrollView.contentOffset = CGPointMake(0, 0);
}
#pragma mark - 课时资源
- (void)rightButtonClick{
    currentIndex = 1;
    _mainScrollView.contentOffset = CGPointMake(_mainw, 0);
    if (!_keChengXueShengZiYuanView) {
        [_mainScrollView addSubview:self.keChengXueShengZiYuanView];
    }
    
}
- (void)backClick{
    [UIView animateWithDuration:0.3 animations:^{
//        self.view.frame= CGRectMake(self->_mainw, 0, self->_mainw, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        self.view = nil;
    }];
    
}
- (UIScrollView *)mainScrollView{
    if (!_mainScrollView) {
        UIScrollView *view = [[UIScrollView alloc]init];
        view.frame = CGRectMake(0, 44, MAINW, APP_HEIGHT-84);
        view.contentSize = CGSizeMake(MAINW*2, 0);
        view.showsHorizontalScrollIndicator = YES;
        view.showsVerticalScrollIndicator = NO;
        view.pagingEnabled = YES;
        view.scrollEnabled = NO;
        view.backgroundColor = MAINBACKCOLOR;
        _mainScrollView = view;
    }
    return _mainScrollView;
}
//#pragma mark - 得到资源
//- (void)getKeChengXueShengLisetRequest{
//    NSDictionary *parama = @{@"classId":_classID};
//    [MBProgressHUD mj_showLoading];
//    [SYRequestAPI sy_getClassStudent:parama success:^(id  _Nonnull responseObject){
//        NSLog(@"教学-课程-未上课时-课程学生 %@",responseObject);
//        self->_classDetailModel = [responseObject objectForKey:@"data"];
//        [MBProgressHUD mj_hideHUD];
//    } fail:^(NSError *error) {
//        [MBProgressHUD mj_hideHUD];
//    }];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
